//
//  AIMacroCommon.h
//  MiaMind
//
//  Created by Vill on 2023/11/23.
//

#ifndef AIMacroCommon_h
#define AIMacroCommon_h

#import "UIView+Extension.h"
#import "UIColor+Extension.h"
#import "NSString+Extension.h"
#import "AIUIHelperManager.h"
#import "AIAESUtil.h"         //解密
#import "UIFont+Extension.h"  //字体
#import "UITextField+Placeholder.h"
#import "AIUserInfoModel.h"   //用户个人信息
#import "AIUserInfoManager.h"
#import "AINetWorkDefine.h"
#import "AIHttpManager.h"

#define KAppDelegate (AppDelegate *)[UIApplication sharedApplication].delegate

#define KImaged(str)    [UIImage imageNamed:str]
#define KUrlImage(str)  [NSURL URLWithString:str]

#define KScreenWidth [UIScreen mainScreen].bounds.size.width
#define KScreenHeight [UIScreen mainScreen].bounds.size.height

#define KNavigationBarHeight \
({ \
    CGFloat navigationBarHeight = 0; \
    if (@available(iOS 11.0, *)) { \
        UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; \
        if (@available(iOS 15.0, *)) { \
            UIEdgeInsets safeAreaInsets = window.safeAreaInsets; \
            navigationBarHeight = safeAreaInsets.top + (safeAreaInsets.top > 0 ? 44 : 0); \
        } else { \
            CGFloat topPadding = window.safeAreaInsets.top; \
            navigationBarHeight = topPadding > 0 ? topPadding + 44 : 64; \
        } \
    } else { \
        navigationBarHeight = 64; \
    } \
    navigationBarHeight; \
})

#define KStatusBarHeight (KNavigationBarHeight - 44)

#define KTabBarHeight \
({ \
    CGFloat tabBarHeight = 0; \
    if (@available(iOS 11.0, *)) { \
        UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; \
        if (@available(iOS 15.0, *)) { \
            UIEdgeInsets safeAreaInsets = window.safeAreaInsets; \
            tabBarHeight = safeAreaInsets.bottom + (safeAreaInsets.bottom > 0 ? 49 : 0); \
        } else { \
            UIEdgeInsets safeAreaInsets = window.safeAreaInsets; \
            tabBarHeight = safeAreaInsets.bottom > 0 ? safeAreaInsets.bottom + 49 : 49; \
        } \
    } else { \
        tabBarHeight = 49; \
    } \
    tabBarHeight; \
})

#define KBottomSafeHeight (KTabBarHeight - 49)
#define PTW(floatValue) (floatValue * KScreenWidth/375.0)

//#define KEY_WINDOW \
//({ \
//    UIWindow *keyWindow = nil; \
//    if (@available(iOS 15.0, *)) { \
//        for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) { \
//            if (windowScene.activationState == UISceneActivationStateForegroundActive) { \
//                keyWindow = windowScene.windows.firstObject; \
//                break; \
//            } \
//        } \
//    } else if (@available(iOS 13.0, *)) { \
//        if ([UIApplication sharedApplication].connectedScenes.count > 0) { \
//            UIWindowScene *windowScene = (UIWindowScene *)[UIApplication sharedApplication].connectedScenes.allObjects.firstObject; \
//            keyWindow = windowScene.windows.firstObject; \
//        } else { \
//            keyWindow = [UIApplication sharedApplication].delegate.window; \
//        } \
//    } else if (@available(iOS 11.0, *)) { \
//        keyWindow = [UIApplication sharedApplication].keyWindow; \
//    } \
//    keyWindow; \
//})

#define WeakSelf(type)  __weak typeof(type) weak##type = type;

#ifdef DEBUG
#define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define NSLog(...)
#endif

#define KDeviceUUID [HDeviceIdentifier deviceIdentifier]

// baseUrl
#define KBASEURL @"http://8.219.52.157:9605"



#endif /* AIMacroCommon_h */
